import java.io.*;
import java.net.*;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.XMLReaderFactory;

class FakeInterface {
	public static void main(String[] args) throws Exception
	{
		if(args.length != 1) {
			System.out.println("Please provide a port.");
			return;
		}//if
		
		Integer serverPort = new Integer(args[0]);
		System.out.println("Binding on port " + serverPort + ".");
		
		
		ServerSocket inSocket;
		try {
			inSocket = new ServerSocket(serverPort.intValue());
		} catch (IOException e) {
			System.err.println("Couldn't bind to port");
			return;
		}//try/catch
		
		
		while(true) {
			try {
				//Wait for connection
				Socket phoneConnection = inSocket.accept();
				VoIPGui phoneGUI = new VoIPGui(phoneConnection);
				EventHandler handler = new EventHandler(phoneConnection, phoneGUI);
				
				EventParser parser = new EventParser();
				MySAXParser myParser = new MySAXParser(parser, phoneConnection);
				while(phoneConnection.isConnected() == true) {
					myParser.parse();

					handler.HandleEvent(parser.event);
				}//while

				phoneGUI.CloseFrame();
				System.out.println("Waiting for next connection");
				
			} catch (IOException e) {
				System.out.println("Got exception: " + e);
				return;
			}

		}//while

	}//main

}//FakeInterface



